/*
 *  TrailMapEditor.cpp
 *  trail-map-editor
 *
 *  Created by Giorgio Tino on 3/4/13.
 *  Copyright 2013 __MyCompanyName__. All rights reserved.
 *
 */

#include "TrailMapEditor.h"

#include "State.h"
#include "MainState.h"
#include "Defines.h"

TrailMapEditor::TrailMapEditor(int argc, char *argv[]) : uiApplication(argc, argv)
{
	current_state = new MainState();
}

TrailMapEditor::TrailMapEditor(int argc, char *argv[], const char* configFile) : uiApplication(argc, argv, configFile)
{
	current_state = new MainState();
}

TrailMapEditor::~TrailMapEditor()
{
    SAFE_DELETE(current_state);
}

void TrailMapEditor::shutdown()
{
    SAFE_DELETE(current_state);

	exit(0);
}

void TrailMapEditor::reshape(int w, int h) 
{ 
	current_state->resize(w,h); 
}

void TrailMapEditor::display() 
{ 
	current_state->display(); 
}

void TrailMapEditor::keyDown(unsigned char key, int x, int y) 
{ 
	current_state->keyDown(key,x,y); 
}

void TrailMapEditor::keyUp(unsigned char key, int x, int y) 
{ 
	current_state->keyUp(key,x,y); 
}

void TrailMapEditor::specialDown(unsigned char key, int x, int y) 
{ 
	current_state->specialDown(key,x,y); 
}

void TrailMapEditor::specialUp(unsigned char key, int x, int y) 
{ 
	current_state->specialUp(key,x,y); 
}

void TrailMapEditor::motion(int newx, int newy) 
{ 
	current_state->motion(newx,newy); 
}

void TrailMapEditor::passive(int newx, int newy) 
{ 
	current_state->passive(newx,newy); 
}

void TrailMapEditor::mouse(int button, int state, int mouseX, int mouseY) 
{ 
	current_state->mouse(button,state,mouseX,mouseY); 
}

void TrailMapEditor::idle()
{
	new_state = current_state->idle();
	
	if(new_state != current_state)
	{
        if(current_state)
            delete current_state;
		
        current_state = new_state;
	}
	
	glutPostRedisplay();
}
